'Initial Review Requirement Script
Option Strict Off
imports System
imports PHSRAG.Insight21.Humans
imports PHSRAG.Insight21.BusinessObjects
imports FormsManagement = PHSRAG.Insight21.FormsManagement

module Script
    sub Main()
		
		'Always add the Sponsor
		Dim sponsorQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Sponsor Funding", FormsManagement.Constants.QuestionnaireType.Forms )
		Dim sponsor as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(sponsorQV.Id, cachePolicy, "Sponsor/Funding", false)
		
		Dim questionnaireAnswers as System.Collections.ArrayList = currentProtVersion.QuestionnaireAnswers
		if questionnaireAnswers.Count > 0 then
		
			Dim initialReviewQA as FormsManagement.QuestionnaireAnswer = questionnaireAnswers(0)
			
			Dim answers as System.Collections.ArrayList = initialReviewQA.GetAnswers("Interaction")
			
			if answers.Count > 0 then
				Dim interactionAnswer as FormsManagement.Answer = answers(0)
					if interactionAnswer.Value = "Yes" then
					
						' Set it as intervention
						theProtocol.IsInterventionStudy = 1
									
						' Study Details
						Dim studyDetQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Study Details", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim studyDetails as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(studyDetQV.Id, cachePolicy, "Study Details", true)

						' Study Population
						Dim studyPopQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Study Population", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim studyPop as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(studyPopQV.Id, cachePolicy, "Study Population", true)

						'PerformanceSites
						Dim performanceSitesQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Performance Sites", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim performanceSites as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(performanceSitesQV.Id, cachePolicy, "Performance Sites / Facilities", true)

						'Recruitment
						Dim recruitmentQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Recruitment", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim recruitment as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(recruitmentQV.Id, cachePolicy, "Recruitment", true)

						'Remuneration
						Dim remunerationQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Remuneration", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim remuneration as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(remunerationQV.Id, cachePolicy, "Remuneration", true)

						'InformedConsent
						Dim informedConsentQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Informed Consent", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim informedConsent as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(informedConsentQV.Id, cachePolicy, "Informed Consent", true)

						'Privacy/Confidentiality
						Dim privacyConfidentialityQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Privacy / Confidentiality", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim privacyConfidentiality as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(privacyConfidentialityQV.Id, cachePolicy, "Privacy / Confidentiality", true)

						'Instruments/Questionnaires
						Dim instrumentsQuestionnairesQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Instruments / Questionnaires", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim instrumentsQuestionnaires as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(instrumentsQuestionnairesQV.Id, cachePolicy, "Instruments / Questionnaires", true)

						'Diaries
						Dim diariesQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Diaries", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim diaries as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(diariesQV.Id, cachePolicy, "Diaries", true)

						'AncillaryDrugs
						Dim ancillaryDrugsQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Ancillary Drugs", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim ancillaryDrugs as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(ancillaryDrugsQV.Id, cachePolicy, "Ancillary Drugs", true)

						'AncillaryDevices
						Dim ancillaryDevicesQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Ancillary Devices", FormsManagement.Constants.QuestionnaireType.Forms )
						Dim ancillaryDevices as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(ancillaryDevicesQV.Id, cachePolicy, "Ancillary Devices", true)

						' Drugs
						answers = nothing
						answers = initialReviewQA.GetAnswers("Drug")
						if answers.Count > 0 then
							Dim drugAnswer as FormsManagement.Answer = answers(0)
							
							if drugAnswer.Value = "Yes" then
								'Add the Drug questionnaire
								Dim drugQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Drugs / Biologics / Dietary Supplements", FormsManagement.Constants.QuestionnaireType.Forms )
								Dim drug as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(drugQV.Id, cachePolicy, FormsManagement.Constants.QuestionnaireAnswerDefaultNames.Drugs, false)
								
							end if
							
						end If
						
						'Devices
						answers = nothing
						answers = initialReviewQA.GetAnswers("Device")
						if answers.Count > 0 then
						
							Dim deviceAnswer as FormsManagement.Answer = answers(0)
							if deviceAnswer.Value = "Yes" then
								Dim deviceQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Medical Devices", FormsManagement.Constants.QuestionnaireType.Forms )
								Dim deviceQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(deviceQV.Id, cachePolicy, FormsManagement.Constants.QuestionnaireAnswerDefaultNames.MedicalDevices, false)		
							end if
						end if
						
						'Children
						answers = nothing
						answers = initialReviewQA.GetAnswers("Children")
						if answers.Count > 0 then
							
							Dim childAnswer as FormsManagement.Answer = answers(0)
							if childAnswer.Value = "Yes" then
								Dim childrenQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Children", FormsManagement.Constants.QuestionnaireType.Forms )
								Dim childrenQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(childrenQV.Id, cachePolicy, FormsManagement.Constants.QuestionnaireAnswerDefaultNames.Children, false)		
							end if
						end if
						
						'Impaired Decision Making
						answers = nothing
						answers = initialReviewQA.GetAnswers("Impaired")
						if answers.Count > 0 then
							
							Dim impairedAnswer as FormsManagement.Answer = answers(0)
							if impairedAnswer.Value = "Yes" then
								Dim impairedQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Impaired Decision Making", FormsManagement.Constants.QuestionnaireType.Forms )
								Dim impairedQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(impairedQV.Id, cachePolicy, "Individuals With Impaired Decision-Making Capacity", false)		
							end if
						end if

						'Pregnant Women or Fetuses
						answers = nothing
						answers = initialReviewQA.GetAnswers("Pregnant")
						if answers.Count > 0 then
							
							Dim pregnantAnswer as FormsManagement.Answer = answers(0)
							if pregnantAnswer.Value = "Yes" then
								Dim pregnantQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Pregnant Women or Human Fetuses", FormsManagement.Constants.QuestionnaireType.Forms )
								Dim pregnantQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(pregnantQV.Id, cachePolicy, "Pregnant Women or Human Fetuses", false)		
							end if
						end if


						'neonates
						answers = nothing
						answers = initialReviewQA.GetAnswers("Neonates")
						if answers.Count > 0 then
							
							Dim neonatesAnswer as FormsManagement.Answer = answers(0)
							if neonatesAnswer.Value = "Yes" then
								Dim neonatesQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Research Involving Neonates", FormsManagement.Constants.QuestionnaireType.Forms )
								Dim neonatesQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(neonatesQV.Id, cachePolicy, "Research Involving Neonates", false)		
							end if
						end if
					
						'ionizing
						answers = nothing
						answers = initialReviewQA.GetAnswers("Ionizing")
						if answers.Count > 0 then
							
							Dim ionizingAnswer as FormsManagement.Answer = answers(0)
							if ionizingAnswer.Value = "Yes" then
								Dim ionizingQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Ionizing Radiation", FormsManagement.Constants.QuestionnaireType.Forms )
								Dim ionizingQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(ionizingQV.Id, cachePolicy, "Ionizing Radiation", false)		
							end if
						end if
						
						'nonionizing
						answers = nothing
						answers = initialReviewQA.GetAnswers("NonIonizing")
						if answers.Count > 0 then
							
							Dim nonIonizingAnswer as FormsManagement.Answer = answers(0)
							if nonIonizingAnswer.Value = "Yes" then
								Dim nonIonizingQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Non-Ionizing Radiation", FormsManagement.Constants.QuestionnaireType.Forms )
								Dim nonIonizingQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(nonIonizingQV.Id, cachePolicy, "Non-Ionizing Radiation", false)		
							end if
						end if
						
						'Nursing
						answers = nothing
						answers = initialReviewQA.GetAnswers("Patients")
						if answers.Count > 0 then
							
							Dim nursingAnswer as FormsManagement.Answer = answers(0)
							if nursingAnswer.Value = "Yes" then
								Dim nursingQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Nursing Implementation and Planning", FormsManagement.Constants.QuestionnaireType.Forms )
								Dim nursingQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(nursingQV.Id, cachePolicy, "Nursing Implementation and Planning", false)		
							end if
						end if

						' Required Protocol Document for intervention studies.
						applicationProtProcess.AddProtocolDocument ( applicationProtProcess.ProtocolId, "Protocol Summary", "ATCHTYPE_PROTOCOLSUMMARY","Protocol Summary", false, applicationProtProcess.Id )
					
					else 
						' Set it as Non intervention
						theProtocol.IsInterventionStudy = 0
					end if
			end if				
				
			'Check for Excess Human Material
			answers = nothing
			answers = initialReviewQA.GetAnswers("Specimens")
			
			if answers.Count > 0 then
				Dim specimenAnswer as FormsManagement.Answer = answers(0)
				if specimenAnswer.Value = "Yes" then
					Dim specimenQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Excess Human Material", FormsManagement.Constants.QuestionnaireType.Forms )
					Dim specimenQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(specimenQV.Id, cachePolicy, "Excess Human Material", false)		
				end if
			end if
			
			'Check for Medical Records only
			answers = nothing
			answers = initialReviewQA.GetAnswers("Records")
			
			if answers.Count > 0 then
				Dim specimenAnswer as FormsManagement.Answer = answers(0)
				if specimenAnswer.Value = "Yes" then
					Dim recordsQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Health / Medical Records", FormsManagement.Constants.QuestionnaireType.Forms )
					Dim recordsQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(recordsQV.Id, cachePolicy, "Health/Medical Records", false)		
				end if
			end if
			
			'Check for Tissue Sample Repository		
			answers = nothing
			answers = initialReviewQA.GetAnswers("Tissue")
			
			if answers.Count > 0 then
				Dim specimenAnswer as FormsManagement.Answer = answers(0)
				if specimenAnswer.Value = "Yes" then
					Dim recordsQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Tissue or Sample Repository", FormsManagement.Constants.QuestionnaireType.Forms )
					Dim recordsQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(recordsQV.Id, cachePolicy, "Tissue or Sample Repository", false)		
				end if
			end if
			
			'Check for Secondary Use
			answers = nothing
			answers = initialReviewQA.GetAnswers("SecondaryUse")
			
			if answers.Count > 0 then
				Dim specimenAnswer as FormsManagement.Answer = answers(0)
				if specimenAnswer.Value = "Y" then
					Dim recordsQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Secondary Use of Research Samples / Data", FormsManagement.Constants.QuestionnaireType.Forms )
					Dim recordsQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(recordsQV.Id, cachePolicy, "Secondary Use of Research Samples / Data", false)		
				end if
			end if			
			
			'Check for RPDR
			answers = nothing
			answers = initialReviewQA.GetAnswers("HelathInformation")
			
			if answers.Count > 0 then
				Dim specimenAnswer as FormsManagement.Answer = answers(0)
				if specimenAnswer.Value = "Yes" then
					Dim recordsQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Research Data Repository", FormsManagement.Constants.QuestionnaireType.Forms )
					Dim recordsQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(recordsQV.Id, cachePolicy, "Research Data Repository", false)		
				end if
			end if

			'Check for Coordinating Center for nonInterventional
			answers = nothing
			answers = initialReviewQA.GetAnswers("Coordinating")
			
			if answers.Count > 0 then
				Dim specimenAnswer as FormsManagement.Answer = answers(0)
				if specimenAnswer.Value = "Y" then
					Dim recordsQV as FormsManagement.QuestionnaireVersion = FormsManagement.Questionnaire.GetActiveVersion( cachePolicy, "Coordinating Center / Core Labs", FormsManagement.Constants.QuestionnaireType.Forms )
					Dim recordsQA as FormsManagement.QuestionnaireAnswer = currentProtVersion.AddNewQuestionnaireAnswer(recordsQV.Id, cachePolicy, "Coordinating Center / Core Labs", false)		
				end if
			end if
			
		end if
				
	   theProtocol.Save( connectionString )
       'currentProtVersion.Save ( connectionString )
       applicationProtProcess.Save( connectionString )

    end sub
end module' VBScript source code